package org.goldfish.distributed_framework.client;

import java.io.Serializable;

public class RpcResponse implements Serializable {
    private static final long serialVersionUID = 1L;

    private Object result;   // 调用返回结果
    private boolean success; // 是否成功
    private String error;    // 错误信息（如果有）

    public RpcResponse() {}

    public RpcResponse(Object result, boolean success, String error) {
        this.result = result;
        this.success = success;
        this.error = error;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    @Override
    public String toString() {
        return "RpcResponse{" +
                "result=" + result +
                ", success=" + success +
                ", error='" + error + '\'' +
                '}';
    }
    // 成功响应
    public static RpcResponse success(Object result) {
        RpcResponse response = new RpcResponse();
        response.setSuccess(true);
        response.setResult(result);
        return response;
    }

    // 失败响应
    public static RpcResponse failure(String errorMessage) {
        RpcResponse response = new RpcResponse();
        response.setSuccess(false);
        response.setError(errorMessage);
        return response;
    }
}
